package com.itheima.service.impl;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.exception.AuthenticationFailedException;
import com.itheima.pojo.LoginDTO;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class MemeberServiceimpl implements MemberService {
@Autowired
    RedisTemplate redisTemplate;
    @Override
    public void login(LoginDTO loginDTO) {
        String phone=loginDTO.getTelephone();
        String code=loginDTO.getValidateCode();
        if (!Objects.equals(code, redisTemplate.opsForValue().get(phone + "Order") )){
            throw new AuthenticationFailedException(MessageConstant.VALIDATECODE_ERROR);
        }
        redisTemplate.delete(phone + "Order");
    }
}
